#include "ToolBarProperty.h"
#include "DisplayWidget.h"
#include <QLabel>
#include <QSpinBox>
#include "ColorComboBox.h"

ToolBarProperty::ToolBarProperty(const QString &title, QWidget *parent)
    :QToolBar(title, parent)
{
    setIconSize(QSize(32, 32));
    initContent();
    centerWidget = nullptr;
}

ToolBarProperty::ToolBarProperty(QWidget *parent)
    :QToolBar(parent)
{
    setIconSize(QSize(32, 32));
    initContent();
    centerWidget = nullptr;
}

void ToolBarProperty::attach(DisplayWidget *widget)
{
    centerWidget = widget;
    connect(spinBoxLineWidth, SIGNAL(valueChanged(int)), centerWidget, SLOT(setLineWidth(int)));
    connect(spinBoxTextSize, SIGNAL(valueChanged (int)), centerWidget, SLOT(setTextSize(int)));
    connect(colorBox, SIGNAL(colorChanged(QColor)), centerWidget, SLOT(setColor(const QColor)));


    connect(actionUndo, SIGNAL(triggered()), centerWidget, SLOT(undo()));
    connect(actionDeleteAll, SIGNAL(triggered()), centerWidget, SLOT(clearAll()));

}

void ToolBarProperty::initContent()
{
    setWindowTitle("Property Setup Toolbar");
    setObjectName(QStringLiteral("ToolBarProperty"));

    QLabel *label = new QLabel(QStringLiteral(" 线条宽度: "), this);
    addWidget(label);
    spinBoxLineWidth = new QSpinBox;
    spinBoxLineWidth->setRange(1, 20);
    spinBoxLineWidth->setValue(2);
    spinBoxLineWidth->setSingleStep(1);
    addWidget(spinBoxLineWidth);
    addSeparator();

    label = new QLabel(QStringLiteral(" 文字大小: "), this);
    addWidget(label);
    spinBoxTextSize = new QSpinBox;
    spinBoxTextSize->setRange(6, 50);
    spinBoxTextSize->setValue(12);
    spinBoxTextSize->setSingleStep(1);
    addWidget(spinBoxTextSize);
    addSeparator();

    colorBox = new ColorComboBox();
    addWidget(colorBox);
    colorBox->setCurrentIndex(1);
    addSeparator();

    actionUndo = new QAction(this);
    actionUndo->setObjectName(QStringLiteral("actionUndo"));
    QIcon icon7;
    icon7.addFile(QStringLiteral(":/measurement/res/undo.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionUndo->setIcon(icon7);
    actionDeleteAll = new QAction(this);
    actionDeleteAll->setObjectName(QStringLiteral("actionDeleteAll"));
    QIcon icon8;
    icon8.addFile(QStringLiteral(":/measurement/res/delete-all.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionDeleteAll->setIcon(icon8);

    addAction(actionUndo);
    addAction(actionDeleteAll);
}
